﻿#pragma once

#include <QObject>
#include <QUrl>

#include "CefWebEngineCore/CefWebEngineCoreGlobal.h"

class CefWebEnginePagePrivate;

class CEFWEBENGINECORE_EXPORT CefWebEnginePage : public QObject
{
    Q_OBJECT

public:
    ~CefWebEnginePage();

    void load(const QUrl &url);
    void reload();
    QUrl url() const;

    void resize(const QSize &size);
    QSize size() const;

    void setTitle(const QString &title);
    QString title() const;

    void setDevToolsPage(CefWebEnginePage *page);

signals:
    void loadStarted();
    void loadProgressChanged(int progress);
    void loadFinished(bool ok);
    void errorOccurred(const QString &error);

    void titleChanged(const QString &title);
    void urlChanged(const QUrl &url);
    void faviconUrlChanged(const QList<QUrl> &urls);
    void statusChanged(const QString &message);
    void toolTipChanged(const QString &message);
    void cursorChanged(const QCursor &cursor);

    void newWindowRequested(const QUrl &url, CefWebEnginePage **page);
    void resizeRequested(const QSize &size, bool &accept);
    void fullScreenRequested(bool fullScreen);
    void renderProcessTerminated();

private:
    CefWebEnginePage(QObject *parent = nullptr);

    void setBrowser(void *browser);
    void *browser() const;
    bool hasBrowser() const;

private:
    Q_DECLARE_PRIVATE(CefWebEnginePage);
    QScopedPointer<CefWebEnginePagePrivate> d_ptr;

    friend class CefWebEngine;
    friend class InternalCefClient;
};